// https://leetcode.cn/problems/shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof/

#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>

using namespace std;

class Solution {
public:
	// 最土的方法
    vector<int> singleNumbers(vector<int>& nums) {
        int len = nums.size();
        vector<int> res;
        sort(nums.begin(), nums.end());
		if(nums[0] != nums[1]){
			res.emplace_back(nums[0]);
		}
        for(int i = 1; i < len-1; i++){
            if(i > 0 && nums[i] != nums[i-1] && i < len-1 && nums[i] != nums[i+1]){
                res.emplace_back(nums[i]);
            }
        }
		if(nums[len-2] != nums[len-1]){
			res.emplace_back(nums[len-1]);
		}
        return res;
    }
	
	vector<int> singleNumbers1(vector<int>& nums) {
        int k;
		for(auto i : nums){
			k ^= i;
		}
		int mask = k & (-k);
		vector<int> res(2);
		for(auto i : nums){
			if(mask & i){
				res[0] ^= i;
			}else {
				res[1] ^= i;
			}
		}
		return res;
    }
};

int main(){
	Solution so;
	vector<int> nums = {1,2,3,3};
	vector<int> res = so.singleNumbers1(nums);
	for(auto i : res){
		cout << i << ",";
	}
	cout << endl;
	return 0;
}